package kz.kstu.scantest.desktop.ui.dialog;

import kz.kstu.scantest.desktop.util.GUIUtils;

import javax.swing.*;
import java.awt.event.*;

public class ReportTypeDialog extends JDialog {

    public final static int ALL = 1;
    public final static int SELECTED = 2;

    private static final int WIDTH = 200;
    private static final int HEIGHT = 150;


    private JPanel contentPane;
    private JButton buttonOK;
    private JRadioButton allRadio;
    private JRadioButton selectedRadio;
    private int reportType;
    private boolean isCanceled = false;

    public ReportTypeDialog() {

    }

    public void initStaticComponent() {
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(allRadio);
        buttonGroup.add(selectedRadio);
        allRadio.setSelected(true);
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);
        setSize(WIDTH, HEIGHT);
        initListeners();
        GUIUtils.centerAndShow(this);
    }


    private void initListeners() {
        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (allRadio.isSelected()) {
                    reportType = ALL;
                } else {
                    reportType = SELECTED;
                }
                dispose();
            }
        });

        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                isCanceled = true;
                dispose();
            }
        });
    }

    public boolean isCanceled() {
        return isCanceled;
    }

    public int getReportType() {
        return reportType;
    }
}
